home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / source / ugly / umemory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  3.6 KB  |  105 lines

  1. /*
  2.  * This source code is part of hsc, a html-preprocessor,
  3.  * Copyright (C) 1993-1997  Thomas Aglassinger
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. #ifndef UGLY_UMEMORY_H
  21. #define UGLY_UMEMORY_H          /* avoid include twice */
  22.  
  23. /*
  24.  * ugly/umemory.h
  25.  *
  26.  * additional memory manegment, tracking and debugging functions, header file
  27.  *
  28.  */
  29.  
  30. #include <stdlib.h>
  31.  
  32. #include "utypes.h"
  33.  
  34. /*
  35.  * ufree() - macro to free memory and set var
  36.  *           pointing to memory to NULL,
  37.  *           but only if it has been allocated
  38.  *           successfully before
  39.  */
  40. struct uglymem
  41. {
  42.     struct uglymem *next;
  43.     void *ptr;                  /* ptr to mem area allocated before */
  44.     UBYTE *lower;               /* lower wall */
  45.     UBYTE *upper;               /* upper wall */
  46.     size_t size;                /* size of this area */
  47.     STRPTR file;                /* filename from which call came */
  48.     ULONG line;                 /* line num in this file */
  49.     UBYTE fillchar;             /* fill character for wall */
  50.  
  51. };
  52.  
  53. typedef struct uglymem UGLYMEM;
  54.  
  55. #if DEBUG_UGLY_MEMORY
  56.  
  57. /* ugly function calls with memory tracking ENABLED */
  58. #define umalloc(size) ugly_malloc_tracking( size, __FILE__, __LINE__ )
  59. #define ufree(ptr)    if ( ptr ) { ugly_free( ptr, __FILE__, __LINE__ ); ptr = NULL; }
  60. #define urealloc(ptr,size) ugly_realloc( ptr, size, __FILE, __LINE__ );
  61. #define ucalloc(count,size) ugly_calloc( count,size,__FILE__,__LINE );
  62.  
  63. #define umem_report(msg) uglymem_report( msg, __FILE__, __LINE__, __DATE__, __TIME__ )
  64. #define umem_stats(msg) uglymem_stats( msg, __FILE__, __LINE__, __DATE__, __TIME__ )
  65. #define umem_wallcheck(msg) uglymem_wallcheck( msg, __FILE__, __LINE__ )
  66.  
  67. #define atexit_uglymemory atexit_uglymemory_real
  68.  
  69. #else
  70.  
  71. /* ugly function calls with memory tracking disabled */
  72. #define umalloc(size) ugly_malloc_notracking(size)
  73. #define ufree(ptr)    if ( ptr ) { free(ptr); ptr=NULL; }       /* TODO: use only free() */
  74. #define urealloc(ptr,size)  realloc( ptr, size );
  75. #define ucalloc(count,size) calloc( count,size )
  76.  
  77. #define umem_report(msg)        /* nufin */
  78. #define umem_stats(msg)         /* nufin */
  79. #define umem_wallcheck(msg)     /* nufin */
  80.  
  81. #define atexit_uglymemory atexit_uglymemory_dummy
  82.  
  83. #endif /* DEBUG_UGLY_MEMORY */
  84.  
  85. #ifndef NOEXTERN_UGLY_UMEMORY_H
  86.  
  87. extern VOID display_panic_message(char *msg, char *file, size_t line);
  88.  
  89. extern void *ugly_malloc_tracking(size_t size, STRPTR file, ULONG line);
  90. extern void *ugly_malloc_notracking(size_t size);
  91. extern void ugly_free(void *ptr, STRPTR file, ULONG line);
  92. extern void *ugly_realloc(void *ptr, size_t size, STRPTR file, ULONG line);
  93. extern void *ugly_calloc(size_t count, size_t size, STRPTR file, ULONG line);
  94.  
  95. extern void uglymem_stats(STRPTR msg, STRPTR file, ULONG line, STRPTR date, STRPTR time);
  96. extern void uglymem_report(STRPTR msg, STRPTR file, ULONG line, STRPTR date, STRPTR time);
  97. extern void uglymem_wallcheck(STRPTR msg, STRPTR file, ULONG line);
  98. extern void atexit_uglymemory(void);
  99.  
  100. extern BOOL(*ugly_nomem_handler) (size_t size);
  101.  
  102. #endif
  103.  
  104. #endif
  105.